-- Haskore Live!
--
-- David Siegel <djsiegel@seas.upenn.edu>
-- Jonathan Coveney <jcoveney@wharton.upenn.edu>
--
-- KeyConfig.hs
--

-- | 'KeyConfig' is used to assign Music atoms to each key on a QWERTY-keyboard.
module KeyConfig ( k_1,k_2,k_3,k_4,k_5,k_6,k_7,k_8,k_9,k_0
                 , k_q,k_w,k_e,k_r,k_t,k_y,k_u,k_i,k_o,k_p
                 ,   k_a,k_s,k_d,k_f,k_g,k_h,k_j,k_k,k_l
                 ,      k_z,k_x,k_c,k_v,k_b,k_n,k_m
                 ) where

import Basics

-- | Describes each row on a QWERTY keyboard.
data Row = Number | Top | Home | Bottom
    deriving (Eq, Show, Ord)

-- | Map from keyboard row to instrument name.
instruments :: [(Row, IName)]
instruments = [ (Number, "Drums")
              , (Top,    "Marimba")
              , (Home,   "Woodblock")
              , (Bottom, "Marimba")
              ]

-- Number row keys:
k_1 = num A  3
k_2 = num B  3
k_3 = num Bs 3
k_4 = num C  4
k_5 = num D  4
k_6 = num Ds 4
k_7 = num E  5
k_8 = num Es 5
k_9 = num F  5
k_0 = num F  5

-- Top row keys:
k_q = top A  3
k_w = top B  3
k_e = top Bs 3
k_r = top C  4
k_t = top D  4
k_y = top Ds 4
k_u = top E  4
k_i = top Es 5
k_o = top F  5
k_p = top F  5

-- Home row keys:
k_a = hom A  3
k_s = hom B  3
k_d = hom Bs 3
k_f = hom C  4
k_g = hom D  4
k_h = hom Ds 4
k_j = hom E  5
k_k = hom Es 5
k_l = hom F  6

-- Bottom row keys:
k_z = bot A  1
k_x = bot B  1
k_c = bot Bs 2
k_v = bot C  2
k_b = bot D  2
k_n = bot Ds 3
k_m = bot E  3

-- Convienience functions for creating notes with note.
num = note (getI Number)
top = note (getI Top)
hom = note (getI Home)
bot = note (getI Bottom)

-- | Given a Row, returns the instrument name associated with that Row in
-- instruments.
getI :: Row -> IName
getI r = maybe "Marimba" id (lookup r instruments)

-- | Shortcut function for constructing a piece of Music representing a single
-- quarter note performed on a given instrument, at a given pitch, in a given
-- octave.
note :: IName -> PitchClass -> Octave -> Music
note i p o = Instr i $ Note (p, o) qn []

